简体   繁体   English

jQuery单击以加载视频/更改缩略图不起作用

[英]jQuery click to load video/change thumbnail not working

bigideahelm bigideahelm

I'm working on this Vimeo integration. 我正在研究这个Vimeo集成。 I'm trying to swap out videos when you click on a particular thumbnail. 当您点击特定缩略图时,我正在尝试换出视频。 Using a quick and dirty method of swapping classes with addClass and removeClass. 使用快速而脏的方法使用addClass和removeClass交换类。 Also swapping out the video with html function. 还使用html函数交换视频。

Trying to do this without reloading the page. 尝试在不重新加载页面的情况下执行此操作。 It looks like the html updates but the videos do not update properly. 它看起来像html更新,但视频无法正确更新。 Anyone have any thoughts? 有人有什么想法?

Here's the HTML: 这是HTML:

    <div class="thumbnails">
        <div class="jake"><img style="display:inline; position: relative;" src="wp-content/themes/skeleton/images/jake.jpg" /></div>
        <div class="katy"><img style="display:inline; position: relative;" src="wp-content/themes/skeleton/images/katy.jpg" /></div>
        <div class="cary"><img style="display:inline; position: relative;" src="wp-content/themes/skeleton/images/cary.jpg" /></div>
    </div>

And the jQuery code (I've only included one section of the code, it's repeated for each video thumbnail): 和jQuery代码(我只包括代码的一部分,它为每个视频缩略图重复):

//CARY
jQuery(".cary").click(function(){
  jQuery('#videoplayer').html('<iframe src="http://player.vimeo.com/video/57695418?api=1" width="470" height="264" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>');

  if(!(jQuery('div').hasClass('jake'))) {
    jQuery('.cary').html('<img style="display:inline; position: relative;" src="wp-content/themes/skeleton/images/jake.jpg" />');
    jQuery('.cary').addClass('jake');
    jQuery('.jake').removeClass('cary');
  }

  if(!(jQuery('div').hasClass('katy'))) {
    jQuery('.cary').html('<img style="display:inline; position: relative;" src="wp-content/themes/skeleton/images/katy.jpg" />');
    jQuery('.cary').addClass('katy');
    jQuery('.katy').removeClass('cary');
  }

  if(!(jQuery('div').hasClass('roderick'))) {
    jQuery('.cary').html('<img style="display:inline; position: relative;" src="wp-content/themes/skeleton/images/roderick.jpg" />');
    jQuery('.cary').addClass('roderick');
    jQuery('.roderick').removeClass('cary');
  }
});

Using the on function seems to update the DOM according and everything seems to be working as intended now. 使用on函数似乎更新了DOM,现在一切似乎都在按预期工作。 I was trying to change elements on the page as opposed to show/hiding elements that are already loaded. 我试图更改页面上的元素,而不是显示/隐藏已加载的元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM