[英]How to get window scroll unit on click .. when a page is animating to top for target position
I need to do parallax scrolling on window scroll and also on navigation click.. In navigation click page is animating on top to show target. 我需要在窗口滚动和导航单击上进行视差滚动。在导航单击页面中,动画在顶部以显示目标。
How to get window scroll unit on click when page is animating to top for target position. 当页面动画到目标位置的顶部时,如何获得单击时的窗口滚动单位。
/*with this code i am trying to get window scroll unit */ / *使用此代码,我试图获取窗口滚动单元* /
$glob(document).ready(function() {
$glob("#lookbook_navi a").bind("click",function(event){
event.preventDefault();
var target = $glob(this).attr("href");
var objWindow = $glob(window);
$window = $glob(window);
alert($window.scrollTop());
$glob("#page").animate({
"top": -($glob(target).position().top)
}, animSpeed);
});
});
/ With this code i am getting unit of window scrolling.. / / 通过此代码,我获得了窗口滚动的单位。
$glob(document).ready(function(){
// Cache the Window object
$window = $glob(window);
$glob('div[data-type="lookBookTab"]').each(function(){
var $bgobj = $glob(this); // assigning the object
$glob(window).scroll(function() {
// Scroll the background at var speed
// the yPos is a negative value because we're scrolling it UP!
var yPos = -($window.scrollTop() / $bgobj.data('speed'));
// Put together our final background position
var coords = '50% '+ yPos + 'px';
// Move the background
$bgobj.css({ backgroundPosition: coords });
}); // window scroll Ends
});
Try this one 试试这个
$('a[href^="#"]').on('click',function (e) {
e.preventDefault();
var target = this.hash,
$target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top
}, 500, 'swing', function () {
window.location.hash = target;
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.