Javascript 猫头鹰转盘未在Elementor live预览中显示
我正在开发一个WordPress网站。有几个部分是我用OWLCarouselJS插件制作的。我正在用Elementor的WordPress页面生成器开发这个网站。它在站点预览中工作正常,但在Elementor Live预览(编辑模式)中不显示 请帮我找个解决办法Javascript 猫头鹰转盘未在Elementor live预览中显示,javascript,php,wordpress,owl-carousel,elementor,Javascript,Php,Wordpress,Owl Carousel,Elementor,我正在开发一个WordPress网站。有几个部分是我用OWLCarouselJS插件制作的。我正在用Elementor的WordPress页面生成器开发这个网站。它在站点预览中工作正常,但在Elementor Live预览(编辑模式)中不显示 请帮我找个解决办法 谢谢。我知道有点晚了,但我也有同样的问题 问题是,owl函数在错误的时间被调用。(我假设在页面加载时) 只需在渲染函数结束时调用owlcarousel,它就可以工作了 像这样: ... 受保护的函数render() { ... if(
谢谢。我知道有点晚了,但我也有同样的问题 问题是,owl函数在错误的时间被调用。(我假设在页面加载时) 只需在渲染函数结束时调用owlcarousel,它就可以工作了 像这样:
...
受保护的函数render()
{
...
if(is_admin())
{
echo“$('.owl carousel').owlCarousel();”;
}
}
if(插件::$instance->editor->is_edit_mode()):?>
$('.owl截图').owlCarousel({
循环:对,
自动播放:对,
差额:10,
导航:错,
点:是的,
导航文本:[“”,“”],
响应:{
0:{
项目:2
},
600:{
项目:3
},
1000:{
项目:4
}
}
})
正如@nukeurself所说,owl函数在错误的时间调用。正如他所提到的,在render()
函数中添加以下行可以使owl函数在正确的时间被调用
if (is_admin()){
echo "<script>$('.owl-carousel').owlCarousel();</script>";
}
虽然这可能是一个很好的答案,但它没有提供任何解释,而且格式也不够好。
if (is_admin()){
echo "<script>$('.owl-carousel').owlCarousel();</script>";
}
...
protected function render()
{
...
if (is_admin())
{
// solves the width issue
// The javascript called after elementor scripts are fully loaded.
if ( ! defined( 'ELEMENTOR_VERSION' ) ) {
return;
}
echo "<script>$('.owl-carousel').owlCarousel();</script>";
}
}