JQuery实用技巧(二)

列高度相同

如果使用了两个CSS列,使用此种方式可以是两列的高度相同。

 
 
  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. });

动态控制页面字体大小

 
 
  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. });

返回页面顶部功能

 
 
  1. $(document).ready(function() {
  2. $('a[href*=#]').click(function() {
  3. if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
  4. && location.hostname == this.hostname) {
  5. var $target = $(this.hash);
  6. $target = $target.length && $target
  7. || $('[name=' + this.hash.slice(1) +']');
  8. if ($target.length) {
  9. var targetOffset = $target.offset().top;
  10. $('html,body')
  11. .animate({scrollTop: targetOffset}, 900);
  12. return false;
  13. }
  14. }
  15. });
  16. // how to use
  17. // place this where you want to scroll to
  18. <A name=top></A>
  19. // the link
  20. <A href="#top">go to top</A>
  21. });

获得鼠标指针XY值

 
 
  1. $(document).ready(function() {
  2. $().mousemove(function(e){
  3. //display the x and y axis values inside the div with the id XY
  4. $('#XY').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY);
  5. });
  6. // how to use
  7. <DIV id=XY></DIV>
  8. });

验证元素是否为空

 
 
  1. $(document).ready(function() {
  2. if ($('#id').html()) {
  3. // do something
  4. }
  5. });

替换元素

 
 
  1. $(document).ready(function() {
  2. $('#id').replaceWith('
  3. <DIV>I have been replaced</DIV>
  4. );
  5. });
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
jQuery是一种基于JavaScript的快速、简洁的JavaScript库,是现在Web开发中广泛应用的工具之一。黑马课件则是一家知名的IT培训机构,该机构开设了jQuery的培训课程。 jQuery的课件黑马课件是一套专门为学习和掌握jQuery的人群准备的教材。这套课件从基础知识开始,介绍了jQuery的语法规则、核心特性和常用方法等。它通过实例讲解和动手实践,帮助学员理解和熟练掌握jQuery的应用。 黑马课件的教学内容包括但不限于以下几个部分:jQuery的引入和初始化、选择器的使用、DOM操作、事件处理、Ajax异步请求等。通过这些内容的学习,学员可以学会如何使用jQuery来简化和优化前端开发工作,实现更加丰富、交互性更高的Web页面。 黑马课件设计的教学方法也非常实用,在课件中穿插了很多实际案例,通过这些案例演示了实际项目中jQuery的应用场景,提供了一个从入门到实践的学习路径。同时,黑马课件还提供了课后练习、实战项目等方式来巩固所学内容,确保学员能够更好地掌握jQuery的使用技巧和应用技术。 总之,jQuery黑马课件是一套结合理论和实践的培训教材,适合想要学习和精通jQuery的人群。它通过系统的课程设计和实例讲解,帮助学员快速入门jQuery,并在实际项目中能够熟练应用。这套课件是一个有价值的学习资源,可以帮助开发者提升前端技术水平。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值