algsupport / yii2-swiperjs-8
yii2 swiper js 8 滑块
Requires
- php: >=8
- npm-asset/swiper: 11.1.14
- yiisoft/yii2: 2.0.45
- dev-main
- v1.0.53
- v1.0.52
- v1.0.51
- v1.0.50
- v1.0.49
- v1.0.48
- v1.0.47
- v1.0.46
- v1.0.45
- v1.0.44
- v1.0.43
- v1.0.42
- v1.0.41
- v1.0.40
- v1.0.39
- v1.0.38
- v1.0.37
- v1.0.36
- v1.0.35
- v1.0.34
- v1.0.33
- v1.0.32
- v1.0.31
- v1.0.30
- v1.0.29
- v1.0.28
- v1.0.27
- v1.0.26
- v1.0.25
- v1.0.24
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- 1.0.0
- dev-renovate/npm-asset-swiper-11.x
- dev-renovate/npm-asset-swiper-8.x
- dev-renovate/yiisoft-yii2-2.x
This package is auto-updated.
Last update: 2024-09-17 06:39:15 UTC
README
关于
这是yii2扩展小部件,用于渲染js滑块 Swiper。这个小部件允许简单地渲染网页中的滑块。为Yii2框架创建。
这个小部件基于 coderius 的工作。
这个存储库的唯一目的是将swiperjs库升级到最新版本。
安装
安装此扩展的首选方式是通过 composer。
首先下载扩展。在终端中运行命令
composer require algsupport/yii2-swiperjs-8:^1.0
或者在composer.json中添加
"algsupport/yii2-swiperjs-8": "^1.0"
然后运行 composer update
用法
具有最小选项的小部件
您只能指定幻灯片的内 容。此参数是必需的。
在所有包含小部件的文件中,将命名空间添加到使用类,例如
<?php
namespace yournamespace
use algsupport\swiperjs8\SwiperSlider;
//Code ...
在视图文件中渲染小部件
<?php
    echo \algsupport\swiperjs8\SwiperSlider::widget([
        'slides' => [
            'one',
            'two',
            'three',
            '<img src="https://swiper.js.cn/demos/images/nature-1.jpg">',
            '<img src="https://swiper.js.cn/demos/images/nature-2.jpg">'
        ],
    ]);
?>
具有更多选项的小部件
您可以自定义小部件的参数
在视图文件中渲染小部件
<?php
    echo \algsupport\swiperjs8\SwiperSlider::widget([
        // 'on ' . \algsupport\swiperjs8\SwiperSlider::EVENT_AFTER_REGISTER_DEFAULT_ASSET => function(){
        //     CustomAsset::register($view);
        // },
        'showScrollbar' => true,
        'slides' => [
            [
                'value' => 'ggg',
                'options' => [
                    'style' => ["background-image" => "url(https://swiper.js.cn/demos/images/nature-1.jpg)"]
                ]
            ],
            '<img src="https://swiper.js.cn/demos/images/nature-2.jpg">',
            'one',
            'two',
            'three',
            'fore',
            'five'
        ],
        // 'assetFromCdn' => true,
        'clientOptions' => [
            'slidesPerView' => 4,
            'spaceBetween'=> 30,
            'centeredSlides'=> true,
            'pagination' => [
                'clickable' => true,
                'renderBullet' => new \yii\web\JsExpression("function (index, className) {
                        return '<span class=\"' + className + '\">' + (index + 1) + '</span>';
                    },
                "),
                ],
                "scrollbar" => [
                    "el" => \algsupport\yii2-swiperjs-8\SwiperSlider::getItemCssClass(SwiperSlider::SCROLLBAR),
                    "hide" => true,
                ],
        ],
        //Global styles to elements. If create styles for all slides
        'options' => [
            'styles' => [
                \algsupport\yii2-swiperjs-8\SwiperSlider::CONTAINER => ["height" => "100px"],
                \algsupport\yii2-swiperjs-8\SwiperSlider::SLIDE => ["text-align" => "center"],
            ],
        ],
            
    ]);
?>
小部件选项
事件:
- EVENT_BEFORE_REGISTER_DEFAULT_ASSET
- EVENT_AFTER_REGISTER_DEFAULT_ASSET
在widget中使用
echo \algsupport\yii2-swiperjs-8\SwiperSlider::widget([
    ...
'on ' . \algsupport\yii2-swiperjs-8\SwiperSlider::EVENT_AFTER_REGISTER_DEFAULT_ASSET => function(){
        CustomAsset::register($view);
},
showScrollbar: true | false。默认为false
showPagination: true | false。默认为true
slides: string | array | . 内容幻灯片内容如  或任何字符串。或者包含键: value,options 的数组。value 可能是字符串或闭包(函数($tag, $index, $self){})。示例
'slides' => [
        [
            'value' => 'ggg',
            'options' => [
                'style' => ["background-image" => "url(https://swiper.js.cn/demos/images/nature-1.jpg)"]
            ]
        ],
        [
            'value' => function($tag, $index, $self){
                return "some value {$index}";
            },
            'options' => [
                'style' => ["color" => "green"]
            ]
        ],
...
clientOptions: array。此选项在初始化Swiper js时粘贴(new Swiper('options here')). 请记住,如果您需要向js插件配置中添加javascript,并且需要纯js,请使用 JsExpression。该类由Yii为此特定目的制作。例如
'clientOptions' => [
    'slidesPerView' => 4,
    'spaceBetween'=> 30,
    'centeredSlides'=> true,
    'pagination' => [
        'clickable' => true,
        'renderBullet' => new \yii\web\JsExpression("function (index, className) {
                return '<span class=\"' + className + '\">' + (index + 1) + '</span>';
            },
        "),
        ],
        "scrollbar" => [
            "el" => \algsupport\yii2-swiperjs-8\SwiperSlider::getItemCssClass(SwiperSlider::SCROLLBAR),
            "hide" => true,
        ],
],
options: array。此选项在渲染DOM元素时粘贴。在此设置html元素的各个属性。此参数仅适用于所有模板项
//Global styles to elements. If create styles for all slides
'options' => [
    'styles' => [
        \algsupport\yii2-swiperjs-8\SwiperSlider::CONTAINER => ["height" => "100px"],
        \algsupport\yii2-swiperjs-8\SwiperSlider::SLIDE => ["text-align" => "center"],
    ],
    'class' => [\algsupport\yii2-swiperjs-8\SwiperSlider::CONTAINER => ["myClass"],]
],
最好使用常量来指定模板元素
- CONTAINER = 'container';
- WRAPPER = 'wrapper';
- SLIDE = 'slide';
- PAGINATION = 'pagination';
- BUTTON_PREV = 'button-prev';
- BUTTON_NEXT = 'button-next';
- SCROLLBAR = 'scrollbar';
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。

