在代码里面写了一个回到顶部的方法,电脑测试 和安卓手机测试完全没问题,在苹果手机上面就会出现点击不会跳转到顶部,反而会向下移一点点;
代码如下(js添加节点并添加点击事件):
js:
if ($('#mkFixedTools').length > 0) {$("<div class='tool-toTop hide'></div>").appendTo('#mkFixedTools');} else {$("<div class='tool-toTop hide'></div>").prependTo("body");}$("body").on("click", ".tool-toTop", function() {$('html,body').animate({scrollTop : '0px'}, 500);return false;});$(window).scroll(function() {var h = (document.documentElement.clientHeight || document.body.clientHeight) * 2.5;if ($(document).scrollTop() >= h) {$(".tool-toTop").removeClass('hide');} else {$(".tool-toTop").addClass('hide');}});
css:
.mkFixedTools {position: fixed;bottom: 61px;right: 12px;z-index: 20; }.mkFixedTools [class^="tool-"] {margin: 0 auto;background-repeat: no-repeat;background-position: center;background-size: 100% 100%; }.mkFixedTools [class^="tool-"] + [class^="tool-"] {margin-top: 6px; }.mkFixedTools .tool-toTop {width: 36px;height: 36px;background-image: url("../image/Btn_Top.png");position: static;bottom: 0;right: 0;}