209 lines
7.1 KiB
JavaScript
209 lines
7.1 KiB
JavaScript
var zy = {};
|
|
|
|
//头部搜索
|
|
zy.top_search_init = function () {
|
|
var mod = $('#mod_top_search');
|
|
var input = mod.find('input:eq(0)');
|
|
mod.find('a.search_btn:eq(0)').on('click', function () {
|
|
if (mod.hasClass('long')) {
|
|
var keyword = input.val();
|
|
var url = input.attr('url');
|
|
if (keyword != '') {
|
|
if (url.indexOf('?') != -1){
|
|
url=url +'&keyword='+ keyword;
|
|
}else{
|
|
url=url +'?keyword='+ keyword;
|
|
}
|
|
$(this).attr('href', url);
|
|
window.location.href = url;
|
|
return true;
|
|
}
|
|
mod.removeClass('long');
|
|
}
|
|
else {
|
|
mod.addClass('long');
|
|
}
|
|
return false;
|
|
});
|
|
input.on('keyup', function (e) {
|
|
if (e.keyCode == 13) { mod.find('a.search_btn:eq(0)').click(); }
|
|
})
|
|
};
|
|
|
|
zy.back_top = function () {
|
|
var btn_back_up = $('#btn_back_top');
|
|
var $left = ($(window).width() + 1100)/2 + 20;
|
|
$(window).bind({
|
|
'resize': function () {
|
|
btn_back_up.css('left', $left);
|
|
},
|
|
'scroll': function () {
|
|
if ($(window).scrollTop() > 0) {
|
|
btn_back_up.css('left', $left).fadeIn(300);
|
|
} else {
|
|
btn_back_up.stop(false, true).fadeOut(300);
|
|
}
|
|
}
|
|
});
|
|
btn_back_up.find('img').on({
|
|
'click': function () {
|
|
$('body, html').animate({scrollTop: 0}, 200);
|
|
},
|
|
'mouseover': function () {
|
|
$(this).attr('ysrc', function () {
|
|
return $(this).attr('src');
|
|
}).attr('src', function () {
|
|
return $(this).data('src');
|
|
});
|
|
},
|
|
'mouseout': function () {
|
|
$(this).attr('src', function () {
|
|
return $(this).attr('ysrc');
|
|
});
|
|
}
|
|
});
|
|
};
|
|
|
|
zy.lazyload_init = function (selector, options) {
|
|
if (!selector) {
|
|
selector = 'img.lazyload, img.lazyload_book_cover, img.lazyload_avatar';
|
|
}
|
|
options = $.extend({data_attribute: 'src', failure_limit: 10, effect: 'fadeIn'}, options ? options : {});
|
|
$(selector).lazyload(options);
|
|
};
|
|
|
|
$(function () {
|
|
|
|
// zy.lazyload_init();
|
|
|
|
zy.back_top();
|
|
|
|
zy.top_search_init();
|
|
|
|
|
|
if($('#btn_index_lb_nv').length > 0){
|
|
//轮播
|
|
$('#btn_index_lb_nv li').on('mouseover', function () {
|
|
var index = $(this).index();
|
|
$(this).addClass('on').siblings('li').removeClass('on');
|
|
var pic = $('#mod_index_lb_nv_pic li:eq(' + index + ')');
|
|
var url = pic.find('a').attr('href');
|
|
var title = pic.find('a').attr('title');
|
|
var desc = $(this).data('desc');
|
|
pic.show().find('img').trigger('lb').end().siblings('li').hide();
|
|
$('#mod_index_lb_nv_txt').find('a').text(title).attr('title', title).attr('href', url)
|
|
.end().find('p').text(desc);
|
|
}).eq(0).mouseover();
|
|
|
|
setInterval(function () {
|
|
var cur_index = $('#btn_index_lb_nv').find('li.on').index();
|
|
var next_index = cur_index == $('#btn_index_lb_nv').find('li').length - 1 ? 0 : cur_index + 1;
|
|
$('#btn_index_lb_nv').find('li:eq(' + next_index + ')').mouseover();
|
|
}, 3000);
|
|
}
|
|
|
|
|
|
$('#mod_login_after').on({
|
|
'mouseover': function () {
|
|
$(this).children('ul').show();
|
|
},
|
|
'mouseout': function () {
|
|
$(this).children('ul').hide();
|
|
}
|
|
});
|
|
|
|
//热门推荐
|
|
$('[mod="hot_tj"] li').on({
|
|
'mouseover': function () {
|
|
$(this).addClass('on')
|
|
},
|
|
'mouseout': function () {
|
|
$(this).removeClass('on');
|
|
}
|
|
});
|
|
|
|
//作品更新
|
|
$('div[mod="btn_book_class"] span').on('click', function () {
|
|
$(this).addClass('on').siblings('span').removeClass('on');
|
|
$(this).parent().next().children('ol:eq(' + ($(this).index() == 2 ? 1 : 0) + ')').addClass('cur').siblings().removeClass('cur');
|
|
}).eq(0).click();
|
|
|
|
//榜单
|
|
$('[mod=rank_data_list] li').on('mouseover', function () {
|
|
$(this).addClass('lis_sh').siblings('li').removeClass('lis_sh');
|
|
});
|
|
|
|
$('.btn_toggle_mod_bang').on('mouseover', function () {
|
|
$(this).css({background: '#c4c4c4', color: '#fff'}).siblings('span').css({background: '#fff', color: '#333'});
|
|
$(this).parent().parent().children('div:eq(' + ($(this).index()-1) + ')').show().siblings('div').hide();
|
|
});
|
|
|
|
//搜索
|
|
$('[btn=search_keyword]').on('click', function () {
|
|
var keyword = $('input[name=search_keyword]').val();
|
|
var url = $('input[name=search_keyword]').attr('url');
|
|
if (keyword != '') {
|
|
if (url.indexOf('?') != -1){
|
|
url=url +'&keyword='+ keyword;
|
|
}else{
|
|
url=url +'?keyword='+ keyword;
|
|
}
|
|
$(this).attr('href', url);
|
|
window.location.href = url;
|
|
return true;
|
|
}
|
|
return false;
|
|
});
|
|
//回车搜索
|
|
$('input[name=search_keyword]').on('keyup', function (e) {
|
|
if (e.keyCode == 13) {
|
|
$('[btn=search_keyword]').click();
|
|
}
|
|
});
|
|
|
|
//详情页作品介绍展开/收起
|
|
var mod_desc = $('#book_desc');
|
|
var height = mod_desc.height();
|
|
var min_height = 54, max_height = 180;
|
|
if (height > min_height) {
|
|
mod_desc.css({height: min_height + 'px'}).next().show().on('click', function () {
|
|
$(this).hide().next().show().end().prev().animate({height: (height < max_height ? max_height : height) + 'px'}, 200);
|
|
}).next().on('click', function () {
|
|
$(this).hide().prev().show().prev().animate({height: min_height + 'px'}, 200);//.css({height: '90px'});
|
|
});
|
|
}
|
|
|
|
//详情页作品介绍展开/收起
|
|
var mod_desc2 = $('#book_desc2');
|
|
var height2 = mod_desc2.height();
|
|
var min_height2 = 54, max_height2 = 180;
|
|
if (height2 > min_height2) {
|
|
mod_desc2.css({height: min_height2 + 'px'}).next().show().on('click', function () {
|
|
$(this).hide().next().show().end().prev().animate({height: (height2 < max_height2 ? max_height2 : height2) + 'px'}, 200);
|
|
}).next().on('click', function () {
|
|
$(this).hide().prev().show().prev().animate({height: min_height2 + 'px'}, 200);//.css({height: '90px'});
|
|
});
|
|
}
|
|
|
|
|
|
//详情页作者其他作品
|
|
$('#mod_other_book_list s').on({'click': function () {
|
|
var is_left = $(this).hasClass('qh_L');
|
|
var is_right = $(this).hasClass('qh_R');
|
|
if (is_left || is_right) {
|
|
var ul = $('#mod_other_book_list ul');
|
|
var width = ul.find('li:eq(0)').outerWidth(true);
|
|
var len = ul.find('li').length;
|
|
var page = ul.data('page') ? Number(ul.data('page')) : 1;
|
|
if (is_left) {
|
|
page = page <= 1 ? 1 : page - 1;
|
|
} else {
|
|
page = page >= len ? len : page + 1;
|
|
}
|
|
var _left = -width*(page-1);
|
|
ul.data('page', page).css({'position': 'relative'}).animate({left: _left}, 300);
|
|
}
|
|
},
|
|
'selectstart': function () { return false; }});
|
|
|
|
}); |