【问题标题】:Mobile site off center when jQuery button is triggered触发jQuery按钮时移动网站偏离中心
【发布时间】:2014-07-19 21:39:41
【问题描述】:

我有一个居中问题,这似乎是由我的动画滚动功能引起的。当按钮被触发时,整个站点变得偏离中心,右侧有填充。这只发生在移动设备/触摸屏上。如果您避开按钮,则不会出现任何问题。

提前感谢您的时间和帮助,我很难过!

Website
Screenshot

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));

【问题讨论】:

标签: javascript jquery mobile padding centering


【解决方案1】:

我遇到了同样的问题!

我的修复:

body{
    width:100%;
    overflow:hidden;
 }

【讨论】:

  • 谢谢,虽然它没有解决问题 :( 但是,我还是应该设置正文宽度,所以我很感激这个建议!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多