【发布时间】:2014-10-09 15:45:57
【问题描述】:
我正在使用一个名为 WideText 的轻量级 jQuery 插件来调整 Bootstrap 3 轮播幻灯片上的标题大小。
它通过添加具有计算出的字体大小的样式来使文本(span class="responsive")适应包含 div 的整个宽度。
当页面加载时,第一张幻灯片的标题会应用字体大小样式。但是当下一张幻灯片进来时,字体大小样式并没有应用。
这里是a picture of the first slide and then the next slide(我没有足够的信誉在这里发布图片)。
我找到了similar issue on Stack Overflow for a different plugin,其想法是在活动幻灯片之后找到下一个项目并调用插件。但我无法使该解决方案发挥作用。
如何将 WideText 插件应用于轮播中的所有字幕,以便它们在每个图像滑入时显示?
这是插件的实际代码:
(function($) {
$.fn.wideText = function() {
return this.each( function() {
// Add "wtext" class to each element and then set up the magic
var obj = $(this),
rtext = obj.addClass( 'wtext' );
// Work that magic each time the browser is resized
$(window).on( 'resize', function() {
obj.css( {'fontSize': parseInt( obj.css('fontSize')) * ( obj.parent().width() / obj.width() ) + 'px', 'visibility' : 'visible' } );
} ).resize();
});
};
} )(jQuery);
这是放在我页面底部的代码:
$(window).load( function() {
$( '.responsive' ).wideText();
} );
谢谢。
【问题讨论】:
标签: javascript jquery html twitter-bootstrap carousel