algsupport/yii2-swiperjs-8 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

algsupport/yii2-swiperjs-8

最新稳定版本:v1.0.89

Composer 安装命令:

composer require algsupport/yii2-swiperjs-8

包简介

yii2 swiper js 8 slider

README 文档

README

About

This is yii2 extention widget renders js slider Swiper. This widget allows render slider in web page simply. Created for Yii2 framework.

This widget is based on the work of coderius.

The sole purpose of this repository is to upgrade the swiperjs library to the latest version.

Yii2 swiper slider widget example

Yii2 swiper slider widget example

Installation

The preferred way to install this extension is through composer.

First download extention. Run the command in the terminal:

composer require algsupport/yii2-swiperjs-8:^1.0

or add in composer.json

"algsupport/yii2-swiperjs-8": "^1.0"

and run composer update

Usage

Widger with minimum options

You can only specify content for slides. This parameter is required.

In all files with widget put namespace to use class like:

<?php
namespace yournamespace

use algsupport\swiperjs8\SwiperSlider;

//Code ...

In view file render widget:

<?php
    echo \algsupport\swiperjs8\SwiperSlider::widget([
        'slides' => [
            'one',
            'two',
            'three',
            '<img src="https://swiperjs.com/demos/images/nature-1.jpg">',
            '<img src="https://swiperjs.com/demos/images/nature-2.jpg">'
        ],
    ]);
?>

Widget with more options:

You can customize the parameters of the widget

In view file render widget:

<?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://swiperjs.com/demos/images/nature-1.jpg)"]
                ]
            ],
            '<img src="https://swiperjs.com/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"],
            ],
        ],
            
    ]);
?>

Widget options

Events:

  • EVENT_BEFORE_REGISTER_DEFAULT_ASSET
  • EVENT_AFTER_REGISTER_DEFAULT_ASSET

Usage in 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. Default is false

showPagination: true | false. Default is true

slides: string | array | . Contents slides content like or any string. Or array with keys: value, options. value maybe like string or Closure (function($tag, $index, $self){}). Example:

'slides' => [
        [
            'value' => 'ggg',
            'options' => [
                'style' => ["background-image" => "url(https://swiperjs.com/demos/images/nature-1.jpg)"]
            ]
        ],
        [
            'value' => function($tag, $index, $self){
                return "some value {$index}";
            },
            'options' => [
                'style' => ["color" => "green"]
            ]
        ],
...

clientOptions: array. This options is pasted when initialize Swiper js (new Swiper('options here')). Please, remember that if you are required to add javascript to the configuration of the js plugin and is required to be plain JS, make use of JsExpression. That class was made by Yii for that specific purpose. For example:

'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. This options is pasted when rendered dom elements. Various attributes for html elements are set here. This params allowed only for all template items:

//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"],]
],

It is best to use constants to specify template elements:

  • CONTAINER = 'container';
  • WRAPPER = 'wrapper';
  • SLIDE = 'slide';
  • PAGINATION = 'pagination';
  • BUTTON_PREV = 'button-prev';
  • BUTTON_NEXT = 'button-next';
  • SCROLLBAR = 'scrollbar';

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 23
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-26