tumblr 上的 vimeo 宽度

发布于 2024-10-14 04:34:38 字数 145 浏览 4 评论 0原文

知道问题 tumblr 将视频宽度限制为 max500,我希望它们为 700。 我已经尝试了列出的所有技巧和脚本,它们不适用于我的主题。有什么建议吗?

Know issue tumblr restricts width of videos to max500, i want them 700.
I've tried all the hacks and scripts listed, they won't work on my theme. Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剩余の解释 2024-10-21 04:34:38

这段代码是一个有用的起点,但它也没有调整嵌入标签的大小,这意味着它不适用于所有浏览器。

<script type="text/javascript">
    $(document).ready(function() {
          var embedTag;
          $('.video').each(function(index) {
               $( this ).contents().each( function ( index ) {
                    if ($(this).is('object') || $(this).is('embed') || $(this).is('iframe')) {
                         var orgWidth = $(this).attr('width');
                         var orgHeight = $(this).attr('height');
                         var scale = orgHeight/orgWidth;
                         var targetWidth = 474;
                         var targetHeight = targetWidth * scale;
                         $(this).attr('width', targetWidth);
                         $(this).attr('height', targetHeight);
                         $(this).find('embed').attr('width', targetWidth);
                         $(this).find('embed').attr('height', targetHeight);
                    }
               });
          });
     });
    </script>

编辑:进一步修订,以防万一您的视频/媒体,无论嵌入其他元素中:

<script type="text/javascript">
    $(document).ready(function() {
          var embedTag;
          $('.video, .media').each(function(index) {
               $( this ).find('object, embed, iframe').each( function ( index ) {
                    var orgWidth = $(this).attr('width');
                    var orgHeight = $(this).attr('height');
                    var scale = orgHeight/orgWidth;
                    var targetWidth = 474;
                    var targetHeight = targetWidth * scale;
                    $(this).attr('width', targetWidth);
                    $(this).attr('height', targetHeight);
                    $(this).find('embed').attr('width', targetWidth);
                    $(this).find('embed').attr('height', targetHeight);
               });
          });
     });
    </script>

This code was a useful starting point, but it didn't resize the embed tag, too, which means it won't work for all browsers.

<script type="text/javascript">
    $(document).ready(function() {
          var embedTag;
          $('.video').each(function(index) {
               $( this ).contents().each( function ( index ) {
                    if ($(this).is('object') || $(this).is('embed') || $(this).is('iframe')) {
                         var orgWidth = $(this).attr('width');
                         var orgHeight = $(this).attr('height');
                         var scale = orgHeight/orgWidth;
                         var targetWidth = 474;
                         var targetHeight = targetWidth * scale;
                         $(this).attr('width', targetWidth);
                         $(this).attr('height', targetHeight);
                         $(this).find('embed').attr('width', targetWidth);
                         $(this).find('embed').attr('height', targetHeight);
                    }
               });
          });
     });
    </script>

EDIT: A further revision, just in case your videos/media, whatever are embedded within other elements:

<script type="text/javascript">
    $(document).ready(function() {
          var embedTag;
          $('.video, .media').each(function(index) {
               $( this ).find('object, embed, iframe').each( function ( index ) {
                    var orgWidth = $(this).attr('width');
                    var orgHeight = $(this).attr('height');
                    var scale = orgHeight/orgWidth;
                    var targetWidth = 474;
                    var targetHeight = targetWidth * scale;
                    $(this).attr('width', targetWidth);
                    $(this).attr('height', targetHeight);
                    $(this).find('embed').attr('width', targetWidth);
                    $(this).find('embed').attr('height', targetHeight);
               });
          });
     });
    </script>
青萝楚歌 2024-10-21 04:34:38

我必须对我为 Tumblr (ridiculouslyawesome.com) 设计/开发的主题做同样的事情。为了绕过 Tumblr 似乎强加的 500px 最大宽度,我想出了一个小小的 javascript hack,它可以找到页面中的所有对象/嵌入/iframe 标签,并根据主题正确调整它们的大小。此示例使用 jQuery,但您可以将其更改为您喜欢使用的任何 JS 框架。

$(document).ready(function() {
      var embedTag;
      $('div.video_container').each(function(index) {
           $( this ).contents().each( function ( index ) {
                if ($(this).is('object') || $(this).is('embed') || $(this).is('iframe')) {
                     var orgWidth = $(this).attr('width');
                     var orgHeight = $(this).attr('height');
                     var scale = orgHeight/orgWidth;
                     var targetWidth = 960;
                     var targetHeight = targetWidth * scale;
                     $(this).attr('width', targetWidth);
                     $(this).attr('height', targetHeight);
                }
           });
      });
 });

到目前为止,在我测试过的所有浏览器中,这对于我的主题来说效果非常好。希望它也对你有用。如果您遇到任何问题,请告诉我。

瑞安

I had to do the same thing with the theme that I designed/developed for my Tumblr (ridiculouslyawesome.com). In order to get around the 500px max width that Tumblr seems to impose, I came up with a little javascript hack that finds all object/embed/iframe tags in the page and resizes them properly for the theme. This example uses jQuery, but you can alter it to whatever JS framework you prefer to use.

$(document).ready(function() {
      var embedTag;
      $('div.video_container').each(function(index) {
           $( this ).contents().each( function ( index ) {
                if ($(this).is('object') || $(this).is('embed') || $(this).is('iframe')) {
                     var orgWidth = $(this).attr('width');
                     var orgHeight = $(this).attr('height');
                     var scale = orgHeight/orgWidth;
                     var targetWidth = 960;
                     var targetHeight = targetWidth * scale;
                     $(this).attr('width', targetWidth);
                     $(this).attr('height', targetHeight);
                }
           });
      });
 });

So far this has worked pretty good for my theme in all the browsers that I have tested it on. Hopefully it will work for you too. Let me know if you run into any issues with it.

Ryan

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文