平稳滑动到页面顶部:
$(function() { if (navigator.userAgent.match(/msie/i) ){ alert('I am an old fashioned Internet Explorer'); } });固定在顶部:
$(function(){ var $win = $(window) var $nav = $('.mytoolbar'); var navTop = $('.mytoolbar').length && $('.mytoolbar').offset().top; var isFixed=0; processScroll() $win.on('scroll', processScroll) function processScroll() { var i, scrollTop = $win.scrollTop() if (scrollTop >= navTop && !isFixed) { isFixed = 1 $nav.addClass('subnav-fixed') } else if (scrollTop <= navTop && isFixed) { isFixed = 0 $nav.removeClass('subnav-fixed') } }检测窗口宽度:
var responsive_viewport = $(window).width(); if (responsive_viewport < 481) { alert('Viewport is smaller than 481px.'); }连接外部自动弹窗:
var root = location.protocol + '//' + location.host; $('a').not(':contains(root)').click(function(){ this.target = "_blank"; });文本框禁止输入空格:
$('input.nospace').keydown(function(e) { if (e.keyCode == 32) { return false; } });