小编sta*_*ler的帖子

Jquery发现图像高度不起作用

我正在尝试使用jQuery来查找容器的第一个"大孩子"的图像高度,然后将容器设置为该高度.但是,我似乎无法拉出图像高度属性 - 让src工作.有任何想法吗?它只是试图通过CSS拉高峰?我如何获得"真正的高度"我无法在img标签中输入宽度和高度 - 所以这不是一个选项;(

 $(document).ready(function() {
       var imageContainer = '#image-container';


       var imageSrc = $(imageContainer).children(':first').children(':first').attr('src'); // control test
       var imageHeight = $(imageContainer).children(':first').children(':first').height(); // have also tried attr('height')

       alert(imageSrc + ' ' + imageHeight);

    });


    <div id="image-gallery">
      <div id="image-container">    

        <div class="slide">
          <img src="test1.jpg" alt="test1" />
          <p>
            <strong>This is a test 1</strong>
          </p>
        </div>

        <div class="slide">
         <img src="test2.jpg" alt="test2" />
         <p>
           <strong>This is a test 2</strong>
         </p>
       </div>

      </div>
    </div>
Run Code Online (Sandbox Code Playgroud)

javascript css jquery height image

8
推荐指数
1
解决办法
6486
查看次数

Fancybox 2自定义标题和标题[来自A(标题)和IMG(alt)

我正在尝试使用带有fancybox 2的图像alt标签中的标题和"标题"...出于某种原因我似乎无法工作......

    $('.fancybox').fancybox({

        beforeShow : function() {
            this.title = '<div class="new-title-title">' + $(this).attr('title') + '</div><div class="new-title-alt">' +  $(this).children('img:first').attr('alt') + '</div>';
        },

        helpers : {
            title: {
                type: 'inner',
                beforeShow: function(opts) {
                    console.log('beforeShow title helper');
                },
            },
        },

    });
Run Code Online (Sandbox Code Playgroud)

来自$(this).attr('title')的标题工作,来自$(this)的字幕.儿童('img:first').attr('alt')说未定义...我知道我必须遗漏一些简单的东西...

javascript jquery fancybox

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

javascript ×2

jquery ×2

css ×1

fancybox ×1

height ×1

image ×1