jq通过宽度调用不同样式

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

<script type="text/javascript">

	$(document).ready(function(){

		$(window).bind("resize", resizeWindow);

		function resizeWindow(e){

			var newWindowWidth = $(window).width();


			// If width width is below 600px, switch to the mobile stylesheet

			if(newWindowWidth < 600){
 				$("link[rel=stylesheet]").attr({href : "mobile.css"});
	 			} 			// Else if width is above 600px, switch to the large stylesheet
 			else if(newWindowWidth > 600){

				$("link[rel=stylesheet]").attr({href : "style.css"});

			}

		}

	});

</script>

 

posted on 2013-06-05 11:42  小猕儿  阅读(232)  评论(0编辑  收藏  举报

导航