$(function() { var picture = $("#picture"), imgPicture = $("#imgPicture"), thumbnail = $(".thumbnail"), picList = $(".pic-list"), picFooter = $(".picture-footer"); function changeAlbum(url){ location.href = url; } function initial() { picFooter.find(".description .number .span2").text($(".pic-list .pic-item").length); picFooter.find(".description .text").text($(".pic-list .pic-item.selected").attr("title")); picFooter.find(".description .tool-button.origin").attr("href", $(".pic-list .pic-item.selected img").attr("src")); } initial(); function mouseUp() { var selectedpicItem = $(".pic-list .pic-item.selected"), picItem = $(".pic-list .pic-item"), selectedInd = selectedpicItem.index(), picItemHeight = picItem.eq(0).outerHeight(true), pervAllLen = selectedInd, picItemLen = picItem.length, nextAllLen = picItemLen - selectedInd - 1; if (selectedInd == 0) { // var url=$(".prev-album").attr("href"); changeAlbum(url); } else { //存在上一个图片; if (pervAllLen >= 2 && nextAllLen >= 2) { //判断 picList.stop().animate({ "top": (-1 * picItemHeight * (selectedInd - 2)) }); } selectedpicItem.removeClass("selected").prev(".pic-list .pic-item").addClass("selected").trigger("click"); } picFooter.find(".description .number .span1").text($(".pic-list .pic-item.selected").index() + 1); initial(); } function mouseDown() { var selectedpicItem = $(".pic-list .pic-item.selected"), picItem = $(".pic-list .pic-item"), selectedInd = selectedpicItem.index(), picItemLen = picItem.length, nextAllLen = picItemLen - selectedInd - 1, picItemHeight = picItem.eq(0).outerHeight(true); picFooter.find(".description .number .span1").text(selectedInd + 2); picFooter.find(".description .number .span2").text(picItemLen); if (selectedInd == picItemLen - 1) { var url = $(".next-album").attr("href"); changeAlbum(url); } else { //存在下一张图片 if (nextAllLen >= 3 && selectedInd >= 1) { //判断当前选中图片的后面的图片数,如果>=3 就上去否则不上去 picList.stop().animate({ "top": (-1 * picItemHeight * selectedInd) }); } selectedpicItem.removeClass("selected").next(".pic-list .pic-item").addClass("selected").trigger("click"); } picFooter.find(".description .number .span1").text($(".pic-list .pic-item.selected").index() + 1); initial(); } $(".prev-album,.next-album").on("click",function(){ //changeAlbum(); }); picFooter.find(".description .tool-button.info").hover(function() { var left = $(this).offset().left, w = $(".pic-list .pic-item.selected img")[0].naturalWidth, h = $(".pic-list .pic-item.selected img")[0].naturalHeight; $(".info-panel .image-size .size").text(w + " X " + h); $(".info-panel").css("left", left).fadeIn(); }, function() { $(".info-panel").fadeOut(); }); picture.on("mousemove", function(e) { var half = (e.pageY - $(this).offset().top) / $(this).outerHeight(); if (half <= 0.5 && !$(this).hasClass("picture-mouse-up")) { $(this).addClass("picture-mouse-up").removeClass("picture-mouse-down"); } else if (half > 0.5 && !$(this).hasClass("picture-mouse-down")) { $(this).addClass("picture-mouse-down").removeClass("picture-mouse-up"); } }); thumbnail.on("click", ".pic-list .pic-item", function() { imgPicture.attr("src", $(this).find("img").attr("src")); $(this).siblings(".pic-item").removeClass("selected").end().addClass("selected"); picFooter.find(".description .text").text($(".pic-list .pic-item.selected").attr("title")); var selectedpicItem = $(".pic-list .pic-item.selected"), picItem = $(".pic-list .pic-item"), selectedInd = selectedpicItem.index(), picItemHeight = picItem.eq(0).outerHeight(true), pervAllLen = selectedInd, picItemLen = picItem.length; nextAllLen = picItemLen - selectedInd - 1; if (selectedInd < 2) { picList.stop().animate({ "top": 0 }); } else if (selectedInd >= 2 && nextAllLen >= 2) { picList.stop().animate({ "top": (-1 * picItemHeight * (selectedInd - 1)) }); } picFooter.find(".description .number .span1").text(selectedInd + 1); picFooter.find(".description .tool-button.origin").attr("href", $(".pic-list .pic-item.selected img").attr("src")); }); $(document).on("click", ".pic-slider .prev-pic,#picture.picture-mouse-up", function() { mouseUp(); }); $(document).on("click", ".pic-slider .next-pic,#picture.picture-mouse-down", function() { mouseDown(); }); $(document).on('mousewheel DOMMouseScroll', onMouseScroll); function onMouseScroll(e) { e.preventDefault(); var wheel = e.originalEvent.wheelDelta || -e.originalEvent.detail; var delta = Math.max(-1, Math.min(1, wheel)); if (delta < 0) { //向下滚动 mouseDown(); } else { //向上滚动 mouseUp(); } } }); /* var imgs = $('#imgs'); $('#searcharea').find('a').eq(0).addClass('ac'); imgs.find('.item').eq(0).addClass('active'); imgs.find('.carousel-indicators li').eq(0).addClass('active'); var liimg = imgs.find(".liimg"); var contentbox = liimg.find('ol'); var type;//图集 $(function () { type = Request("type"); $.Search(); }); function page(v) { //var l = liimg.height() * v * -1 + parseInt(contentbox.css("top")); //if (l >= 0) { // liimg.prev().addClass("disabled"); //} else { // liimg.prev().removeClass("disabled"); //} //if (l + contentbox.height() - liimg.height() < 0) { // liimg.next().addClass("disabled"); //} else { // liimg.next().removeClass("disabled"); //} //if (l > 0 || l + contentbox.height() < 0) // return; contentbox.stop().animate({ top: 'l00px' }, 1000); }*/