【发布时间】:2011-12-06 08:03:36
【问题描述】:
您好 — 首先,我对 jquery 还很陌生,因此非常感谢您扩展的专业知识。
演示:http://www.transcendspace.com/beta/
我想为我的 div 生成一个导航:1|2|3|4|5 等,它会根据哪个 div 处于活动状态来突出显示数字。理想情况下,突出显示将与我的左/右箭头结合使用。
代码:`
$(document).ready(function() {
$(window).resize(function () {
resizePanel();
});
});
function resizePanel() {
width = $(window).width();
height = $(window).height();
mask_width = width * $('.item').length;
$('#debug').html(width + ' ' + height + ' ' + mask_width);
$('#wrapper, .item').css({width: width, height: height});
$('#mask').css({width: mask_width, height: height});
$('#wrapper').scrollTo($('a.selected').attr('href'), 0);
}
function scrollToPosition(element) {
if (element !== undefined) {
$("#wrapper").scrollTo(element, 800, {});
}
}
$(function() {
//Create an Array of posts
var posts = $('.item');
var position = 0; //Start Position
var next = $('#next');
var prev = $('#prev').hide();
//Better performance to use Id selectors than class selectors
next.click(function(evt) {
//Scroll to next position
prev.show();
scrollToPosition(posts[position += 1]);
if (position === posts.length - 1) {
next.hide();
}
});
prev.click(function(evt) {
//Scroll to prev position
next.show();
scrollToPosition(posts[position -= 1]);
if (position === 0) {
prev.hide();
}
});
});
</script>'
【问题讨论】:
标签: jquery html navigation scrollto