thomhines/square1
Composer 安装命令:
composer require thomhines/square1
包简介
Square1 jQuery slider (JS/CSS image/content slider with responsive srcset support).
README 文档
README
A very simple jQuery image/content slider that responsively handles images of any size or shape.
Requires jQuery
Demo
Installation
1) Manual installation
Download or copy the project files into your web-accessible assets directory, then load jQuery and Square1:
<script src="https://code.jquery.com/jquery-1.0.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script> <link rel="Stylesheet" href="/path/to/square1/square1.min.css" type="text/css" /> <script src="/path/to/square1/square1.min.js"></script>
2) Composer (Packagist)
Install with Composer:
composer require thomhines/square1
Then include files from your Composer vendor directory:
<script src="https://code.jquery.com/jquery-1.0.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script> <link rel="Stylesheet" href="/vendor/thomhines/square1/square1.min.css" type="text/css" /> <script src="/vendor/thomhines/square1/square1.min.js"></script>
3) Git submodule
Add Square1 as a submodule:
git submodule add https://github.com/thomhines/square1.git vendor/square1 git submodule update --init --recursive
Then include it in your page:
<script src="https://code.jquery.com/jquery-1.0.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script> <link rel="Stylesheet" href="/vendor/square1/square1.min.css" type="text/css" /> <script src="/vendor/square1/square1.min.js"></script>
Usage
HTML
Each direct child of the slideshow container is wrapped in an internal slide element. You can use a flat list of images:
<div class="slideshow"> <img src="image1.png" alt="Short label" caption="Longer caption text"> <img data-src="image2.png" alt="Short label" caption="Caption 2"> <img data-src="image3.png" alt="Short label" caption="Caption 3"> </div>
caption— optional; used by the caption UI when enabled (in addition toalt).data-src/data-srcset— optional data- prefix delays loading until Square1 promotes them tosrc/srcset(sequential loading). Pair with thelazy_loadoption to load each slide only when needed.srcset/sizes— optional; native responsive selection applies to visible images.scale-from/scale-from-mobile— optional per-imageobject-position; on narrow viewports (under 600px),scale-from-mobilewins when present.space— optional; copied onto the slide wrapper for advanced filtering (see globalfilter_galleryin the script if you use tagged slides).
Or use rich slides (first <img> in each child is the photo layer; remaining markup is overlaid or non-image slides without an <img>):
<div class="slideshow"> <div> <img src="image1.png" alt="Caption 1"> <h3>Slide title</h3> </div> <div> <img src="image2.png" alt="Caption 2"> <h3>Slide title</h3> </div> </div>
JavaScript
$(function() { $('.slideshow').square1(); });
Slideshow options
Pass an object of overrides to square1():
$('.slideshow').square1({ slide_duration: 8000, dots_nav: 'hover' });
Defaults and meanings (see square1.js for inline comments):
| Option | Default | Description |
|---|---|---|
width |
'' |
Any CSS width. Blank uses stylesheet / block layout (demo uses full width). |
height |
'' |
Any CSS height. When blank and aspect_ratio is also blank, the first decoded image sets aspect-ratio on the root so the box gets a height. |
aspect_ratio |
'' |
Any valid CSS aspect-ratio (e.g. '16/9', '1.3'). When set, height is applied as auto so the box sizes from width and this ratio. |
animation |
'fade' |
'fade' or 'slide'. |
fill_mode |
'cover' |
'cover' or 'contain' — maps to object-fit on slide images. |
scale_from |
'center center' |
Default object-position for images (same keyword grammar as CSS). |
start_delay |
0 |
Milliseconds before autoplay when auto_start is true. |
slide_duration |
4000 |
Milliseconds each slide stays visible. |
transition_time |
500 |
Transition duration in ms. |
lazy_load |
false |
When true, does not pre-load the sequential chain; images load when needed (still use data-src / data-srcset where appropriate). |
auto_start |
true |
Start the timer automatically. |
pause_on_hover |
false |
Pause autoplay while the pointer is over the slideshow. |
keyboard |
true |
Arrow keys; tabindex is set when enabled. |
gestures |
true |
Swipe to change slides on touch devices. |
theme |
'dark' |
'dark' or 'light' UI chrome. |
background |
'none' |
CSS background on the slideshow root. |
prev_next_nav |
'inside' |
'inside', 'outside', 'hover', or 'none'. |
dots_nav |
'inside' |
Same choices as arrows. |
caption |
'outside' |
'inside', 'outside', 'hover', or 'none' — uses the caption attribute when present. |
onLoad |
function () {} |
Fires when all slides have finished loading. |
onPlay |
function () {} |
Fires when playback starts. |
onStop |
function () {} |
Fires when playback stops. |
onChange |
function () {} |
Fires after the active slide changes. |
Remote control
$('.slideshow').square1('play'); $('.slideshow').square1('stop'); $('.slideshow').square1('next'); $('.slideshow').square1('prev'); $('.slideshow').square1(5); // jump to slide 5 (1-based index)
License
Square1 is released under the MIT License. See the LICENSE file for full text.
Thanks
Thanks to the following image providers used in the demos:
thomhines/square1 适用场景与选型建议
thomhines/square1 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 9, 最近一次更新时间为 2026 年 04 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「jquery」 「javascript」 「css」 「frontend」 「slider」 「carousel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 thomhines/square1 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 thomhines/square1 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 thomhines/square1 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.
A Twig extension to insert css as inline styles with a tag
Caching and compression for Twig assets (JavaScript and CSS).
A pretty nice way to expose your translation messages to your JavaScript.
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
PHP client for the Google Closure Compiler API in one file.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 46
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-16