$(function(){ $(".gotop").click(function(){ $("html,body").stop().animate({scrolltop:0},1000) }) $('.pop-close, .pop-overlay').on('click', function(e){ e.stoppropagation(); $(this).parents('.pop-mod').removeclass('x-show'); enwinscroll(); }); /// }); /* function */ /* container满屏高度设置 */ function screencontainer(cls){ // cls-[字符串] 类名(不要加‘.’) 当x-container设置此类名时,函数不会为x-container添加padding值来填充x-header的高度 var container = $('.x-container'); var syncele = $(container.data('sync')); var header = $('.x-header'); var footer = $('.x-footer'); foo(); function foo(){ var wheight = $(window).height(); var hheight = header.innerheight(); var fheight = footer.innerheight(); if(header.css('position') === 'fixed' || header.css('position') === 'absolute'){ if(container.hasclass(cls)){ container.css({'min-height' : wheight - fheight + 'px'}); syncele.css({'height' : wheight - fheight + 'px'}); }else{ if(container.css('box-sizing') === 'border-box'){ container.css({'min-height' : wheight - fheight + 'px', 'padding-top' : hheight + 'px'}); syncele.css({'height' : wheight - fheight + 'px', 'padding-top' : hheight + 'px'}); }else{ container.css({'min-height' : wheight - fheight - hheight + 'px', 'padding-top' : hheight + 'px'}); syncele.css({'height' : wheight - fheight - hheight + 'px', 'padding-top' : hheight + 'px'}); } } }else{ container.css({'min-height' : wheight - fheight - hheight + 'px'}); syncele.css({'height' : wheight - fheight - hheight + 'px'}); } } $(window).on('load', foo); $(window).on('resize', foo); } /* fixed定位元素的横向滚动显示 */ function scrollposfix(ele){ // ele-[字符串] 类名(不要加‘.’) foo(); $(window).on('scroll', foo); function foo(){ var posele = $('.'+ele); if($(window).scrollleft()>0){ if(posele.hasclass(ele)){ posele.css('margin-left', -$(window).scrollleft() + 'px'); }else{ posele.css('margin-left', '0px'); posele = null; } } } } /* 返回顶部 */ function gotop(cls){ // cls-[字符串] 类名 $(cls).on('click', function(){ $('body, html').stop().animate({scrolltop: 0}, 400 + $(window).scrolltop() * 0.3); }); } /* 获取滚动条宽度 */ function getscrollbarwidth(){ var rw = 0, wh = 0, bh = 0; wh = $(window).height(); bh = $('body').height(); if(bh > wh){ if(!$('body').data('scrollbarwidth')){ $('body').append(''); rw = 100-$('.fnscrollbarinner').width(); $('body').data('scrollbarwidth', rw); $('.fnscrollbarwrap').remove(); }else{ rw = $('body').data('scrollbarwidth'); } } return rw; } // 打开弹窗 function popshow(ele){ $(ele).addclass('x-show'); unwinscroll(); } // 关闭弹窗 function pophide(){ $('.pop-mod').removeclass('x-show'); enwinscroll(); } /* 禁止窗口滚动 */ function unwinscroll(){ var top = $(window).scrolltop(); $('body').css({'position':'fixed','top':-top + 'px','left':'0px','right':getscrollbarwidth() + 'px'}).data('winscroll',top); } /* 释放窗口滚动 */ function enwinscroll(){ $('body').removeattr('style'); $(window).scrolltop($('body').data('winscroll')); } /* 禁止选中 */ function unselect(ele){ // ele-[字符串] 操作对象,通常设为body $(ele).attr('unselectable','on').css({ '-moz-user-select':'-moz-none', '-moz-user-select':'none', '-o-user-select':'none', '-khtml-user-select':'none', /* you could also put this in a class */ '-webkit-user-select':'none',/* and add the css class here instead */ '-ms-user-select':'none', 'user-select':'none' }).on('selectstart', function(){ return false; }); } /* 释放选中 */ function enselect(ele){ // ele-[字符串] 被禁止选中的对象 $(ele).attr('unselectable','off').css({ '-moz-user-select':'text', '-moz-user-select':'text', '-o-user-select':'text', '-khtml-user-select':'text', /* you could also put this in a class */ '-webkit-user-select':'text',/* and add the css class here instead */ '-ms-user-select':'text', 'user-select':'text' }).off('selectstart'); } /* ******************************************************************************************************************* */