我有一个显示座位表的网页(每个座位都是一个div)。在某些情况下,页面很大,因此您可能必须向右或向下滚动才能找到座位。
我有一个包含座位名称的链接(这是您座位的div的ID)。我想要一些在页面加载时“发现”并“突出显示”您座位的jquery代码。
加载页面时,最好的滚动方式是将某个div置于页面的中心,这是最好的方法。一旦到达该位置,我便可以执行一些操作,例如暂时使div高以使其脱颖而出。
工作示例: http : //jsfiddle.net/wonq8es4/3/
上面的示例滚动到div
页面上的一个随机位置。
// Get a random div or seat
var seat = $('#div' + randInt.toString());
// Slowly scroll to the top of the div element
$('html,body').animate({
scrollTop: seat.offset().top-20,
scrollLeft: seat.offset().left-20
},'slow');
// When the animation has completed hide,
// change the background color, and fade in the div
$('html,body').promise().done(function(){
seat.hide().css('background','yellow').fadeIn(1000);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句