无法将OwlCarousel添加到laravel项目中,并且不起作用。我该怎么办?
我复制owl.carousel.min.css
并owl.theme.default.min.css
和owl.carousel.min.js
对owlcarousel
那被放置在同一个目录中的文件夹view.blade.php
的文件了。
我的代码是:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<link rel="stylesheet" href="owlcarousel/owl.carousel.min.css">
<link rel="stylesheet" href="owlcarousel/owl.theme.default.min.css">
</head>
<body>
<div class="owl-carousel">
<div> Your Content</div>
<div> Your Content</div>
<div> Your Content</div>
<div> Your Content</div>
<div> Your Content</div>
<div> Your Content</div>
<div> Your Content</div>
</div>
<script>
$(document).ready(function () {
$(".owl-carousel").owlCarousel();
});
</script>
<script src="owlcarousel/owl.carousel.min.js"></script>
</body>
</html>
正确的方法是这样的:
<script type="text/javascript" src="{{ URL::asset('js/owl.min.js') }}"></script>
URL :: asset()函数为您生成必要的url。对于CSS同样:
<link rel="stylesheet" href="{{ URL::asset('css/owl.css') }}" />
您必须将owlcarousel
文件夹放置在laravel的app/public
文件夹中,而不是在views文件夹中。希望这可以帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句