5. 预加载图片
view plaincopy to clipboardprint?
1. $(document).ready(function() {
2. jQuery.preloadImages = function()
3. {
4. for(var i = 0; i").attr("src", arguments[i]);
5. }
6. };
7. // how to use
8. $.preloadImages("image1.jpg");
9. });
6. 页面样式切换
view plaincopy to clipboardprint?
1. $(document).ready(function() {
2. $("a.Styleswitcher").click(function() {
3. //swicth the LINK REL attribute with the value in A REL attribute
4. $('link[rel=stylesheet]').attr('href' , $(this).attr('rel'));
5. });
6. // how to use
7. // place this in your header
8. <LINK href="default.css" type=text/css rel=stylesheet>
9. // the links
10. <A class="Styleswitcher" href="#" rel=default.css>Default Theme</A>
11. <A class="Styleswitcher" href="#" rel=red.css>Red Theme</A>
12. <A class="Styleswitcher" href="#" rel=blue.css>Blue Theme</A>
13. });
7. 列高度相同
如果使用了两个CSS列
,使用此种方式可以是两列的高度相同
。view plaincopy to clipboardprint?
1. $(document).ready(function() {
2. function equalHeight(group) {
3. tallest = 0;
4. group.each(function() {
5. thisHeight = $(this).height();
6. if(thisHeight > tallest) {
7. tallest = thisHeight;
8. }
9. });
10. group.height(tallest);
11. }
12. // how to use
13. $(document).ready(function() {
14. equalHeight($(".left"));
15. equalHeight($(".right"));
16. });
17. });
8. 动态控制页面字体大小
用户可以改变页面字体大小
view plaincopy to clipboardprint?
1. $(document).ready(function() {
2. // Reset the font size(back to default)
3. var originalFontSize = $('html').css('font-size');
4. $(".resetFont").click(function(){
5. $('html').css('font-size', originalFontSize);
6. });
7. // Increase the font size(bigger font0
8. $(".increaseFont").click(function(){
9. var currentFontSize = $('html').css('font-size');
10. var currentFontSizeNum = parseFloat(currentFontSize, 10);
11. var newFontSize = currentFontSizeNum*1.2;
12. $('html').css('font-size', newFontSize);
13. return false;
14. });
15. // Decrease the font size(smaller font)
16. $(".decreaseFont").click(function(){
17. var currentFontSize = $('html').css('font-size');
18. var currentFontSizeNum = parseFloat(currentFontSize, 10);
19. var newFontSize = currentFontSizeNum*0.8;
20. $('html').css('font-size', newFontSize);
21. return false;
22. });
23. });