gpt4 book ai didi

javascript - jQuery 文本大小调整插件仅适用于 Bootstrap 轮播的第一张幻灯片

转载 作者:行者123 更新时间:2023-11-28 01:03:35 28 4
gpt4 key购买 nike

我正在使用一个名为 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();
} );

谢谢。

最佳答案

好的,在 Jquery 专业人士进行一些故障排除之后,我们想出了这段额外的代码。

// auto type width adjustment in #primary-carousel images   
$(window).load( function() {
$( 'h1 span.responsive' ).wideText();
} );

// hack for invisible carousel wideText timing problem
// boostrap carousel sends an event "slide.bs.carousel" when it begins to slide
$('#primary-carousel').on("slide.bs.carousel", function(){
setTimeout(function(){
$(window).trigger('resize');
}, 40);
})

关于javascript - jQuery 文本大小调整插件仅适用于 Bootstrap 轮播的第一张幻灯片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25334343/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com