【发布时间】:2014-07-19 21:39:41
【问题描述】:
我有一个居中问题,这似乎是由我的动画滚动功能引起的。当按钮被触发时,整个站点变得偏离中心,右侧有填充。这只发生在移动设备/触摸屏上。如果您避开按钮,则不会出现任何问题。
提前感谢您的时间和帮助,我很难过!
HTML
<div id="scroll" onclick="$('#projects').animatescroll();">
<img src="img/arrow.png" class="image" alt="scroll down" width="65px;" />
</div>
JS
(function($){
// defines various easing effects
$.easing['jswing'] = $.easing['swing'];
$.extend( $.easing,
{
def: 'easeOutQuad',
swing: function (x, t, b, c, d) {
return $.easing[$.easing.def](x, t, b, c, d);
},
easeOutQuad: function (x, t, b, c, d) {
return -c *(t/=d)*(t-2) + b;
},
});
$.fn.animatescroll = function(options) {
// fetches options
var opts = $.extend({},$.fn.animatescroll.defaults,options);
// make sure the callback is a function
if (typeof opts.onScrollStart == 'function') {
// brings the scope to the callback
opts.onScrollStart.call(this);
}
if(opts.element == "html,body") {
// Get the distance of particular id or class from top
var offset = this.offset().top;
// Scroll the page to the desired position
$(opts.element).stop().animate({ scrollTop: offset - opts.padding}, opts.scrollSpeed, opts.easing);
}
else {
// Scroll the element to the desired position
$(opts.element).stop().animate({ scrollTop: this.offset().top - this.parent().offset().top + this.parent().scrollTop() - opts.padding}, opts.scrollSpeed, opts.easing);
}
setTimeout(function() {
// make sure the callback is a function
if (typeof opts.onScrollEnd == 'function') {
// brings the scope to the callback
opts.onScrollEnd.call(this);
}
}, opts.scrollSpeed);
};
// default options
$.fn.animatescroll.defaults = {
easing:"swing",
scrollSpeed:800,
padding:0,
element:"html,body"
};
}(jQuery));
【问题讨论】:
-
“调试我的网站”问题只有一个网站链接可能会被关闭,因为一旦你解决了问题,这个问题对于以后遇到同样问题的任何人来说都是无用的。有关如何改进问题的说明,请参阅Something in my web site or project doesn't work. Can I just paste a link to it?
-
谢谢@Juhana,我会在我的问题中添加相关代码:)
标签: javascript jquery mobile padding centering