1. CSS仿寫實心三角特效
<div class="triangle"></div> // 實心倒三角
.triangle {
margin: 15px 0 0 130px; // 調整位置
position: absolute;
border: 10px solid white;
border-left-color: transparent;
border-bottom-color: transparent;
border-right-color: transparent;
}
複製代碼
2. Angular美化原生select的下拉選項樣式(空心下拉上拉箭頭)
<div class="triangle"><div [ngClass]="arrow && i == selectIndex?'inner-up':'inner-down'"></div></div>
<select (blur)="selectBlur(i)" (click)="selectClick(i)">
<option [value]="participant.id">{{name}}</option>
</select>
複製代碼
.triangle{
position: absolute;
margin-left: 220px;
margin-top: 10px;
.inner-down {
width: 8px;
height: 8px;
border: 1px solid #CACFD2;
border-width: 1px 1px 0 0;
transform: rotate(135deg);
margin-bottom: 10px;
margin-top: -5px;
}
.inner-up {
width: 8px;
height: 8px;
border: 1px solid #CACFD2;
border-width: 0 0 1px 1px;
transform: rotate(135deg);
margin-bottom: 10px;
}
}
複製代碼
3. Angular - 仿video的拖拉滑動條
原生JavaScript寫法:
js原生仿水平拖動軸
<div class="scroll" id="scroll">
<div class="bar" id="bar"></div>
<div class="mask" id="mask"></div>
</div>
複製代碼
.scroll {
width: 70%;
height: 5px;
background: #d9e4e7;
position: relative;
margin-top: 15px;
border-radius: 5px;
}
.bar {
width: 20px;
height: 20px;
background: #fff;
position: absolute;
top: -7px;
left: 0;
cursor: pointer;
border-radius: 50%;
}
.mask {
position: absolute;
left: 0;
top: 0;
background: #3498db;
width: 0;
height: 5px;
border-radius: 5px;
}
複製代碼
- angular6不能直接經過document對象去操做頁面對象!須要以angular特有的方式操做:
1. import { ElementRef } from '@angular/core';
2. constructor( public element: ElementRef ) { }
3. 經過 **this.element.nativeElement.querySelector('#scroll'); 操做對象!**
videoProgress() {
const _that = this;
const scroll = this.element.nativeElement.querySelector('#scroll');
const bar = this.element.nativeElement.querySelector('#bar');
const mask = this.element.nativeElement.querySelector('#mask');
bar.onmousedown = function (event) {
let barleft = 0;
const leftVal = event.clientX - this.offsetLeft;
document.onmousemove = function (event2) {
barleft = event2.clientX - leftVal;
if (barleft < 0) {
barleft = 0;
} else if (barleft > scroll.offsetWidth - bar.offsetWidth) {
barleft = scroll.offsetWidth - bar.offsetWidth;
}
mask.style.width = barleft + 'px';
bar.style.left = barleft + 'px';
_that.currentTime = (barleft / (scroll.offsetWidth - bar.offsetWidth)) * (_that.getPlayBackTotalTime);
if (window.getSelection) {
if (window.getSelection().empty) {
window.getSelection().empty();
} else if (window.getSelection().removeAllRanges) {
window.getSelection().removeAllRanges();
}
}
}
document.onmouseup = function () {
document.onmousemove = null;
}
}
}
複製代碼
4. 原生仿寫video播放器
<div class="control-wrapper">
<div class="v-pause-play-button">
<img src="./image/video-stop.png" alt="" class="c-icon" id="videoControl">
</div>
<div class="scroll" id="scroll">
<div class="bar" id="bar"></div>
<div class="mask" id="mask"></div>
</div>
<div class="c-time"><span id="c_time_info"></span>/<span id="t_time_info"></span></div>
<div><img src="./image/voice.svg" alt="" class="c-icon"></div>
<div class="scroll_voice" id="scroll_voice">
<div class="bar_voice" id="bar_voice"></div>
<div class="mask_voice" id="mask_voice"></div>
</div>
</div>
複製代碼
.control-wrapper{
user-select: none;
height: 40px;
line-height: 40px;
width: 100%;
background-color: #000;
border: 1px solid gray;
display: flex;
justify-content: space-between;
}
/* 總進度條 */
.scroll {
width:75%;
height: 6px;
background: #d9e4e7;;
position: relative;
margin: 0 auto;
margin-top: 15px;
border-radius: 5px;
z-index: 999;
}
/* 控制手柄圈圈 */
.bar {
width: 15px;
height: 15px;
background: #fff;
position: absolute;
top: -5px;
left: 0;
cursor: pointer;
border-radius: 50%;
}
/* 已走過的進度 */
.mask {
position: absolute;
left: 0;
top: 0;
background: #3498db;
width: 0;
height: 6px;
border-radius: 5px;
}
/* 音量進度條 */
.scroll_voice{
width:100px;
height: 6px;
background: #d9e4e7;;
position: relative;
margin: 0 auto;
margin-top: 15px;
border-radius: 5px;
z-index: 999;
margin-right: 15px;
}
/* 控制手柄圈圈 */
.bar_voice {
width: 15px;
height: 15px;
background: #fff;
position: absolute;
top: -5px;
left: 0;
cursor: pointer;
border-radius: 50%;
}
/* 已走過的進度 */
.mask_voice {
position: absolute;
left: 0;
top: 0;
background: #3498db;
width: 0;
height: 6px;
border-radius: 5px;
}
複製代碼
function videoProgress() {
let barleft = 0;
bar.onmousedown = function (event) {
var event = event || window.event;
var leftVal = event.clientX - this.offsetLeft;
$('body').on('mousemove', function () {
var event = event || window.event;
barleft = event.clientX - leftVal;
if (barleft < 0) {
barleft = 0;
} else if (barleft > scroll.offsetWidth - bar.offsetWidth) {
barleft = scroll.offsetWidth - bar.offsetWidth;
}
drag_playPercent = parseInt(barleft / (scroll.offsetWidth - bar.offsetWidth) * 100);
mask.style.width = drag_playPercent + '%';
bar.style.left = drag_playPercent + "%";
})
$('body').on('mouseup', function () {
$('body').off();
...
})
}
}
function videoVoiceProgress() {
let barleft = 0;
bar_voice.onmousedown = function (event) {
var event = event || window.event;
var leftVal = event.clientX - this.offsetLeft;
$('body').on('mousemove', function (event) {
var event = event || window.event;
barleft = event.clientX - leftVal;
if (barleft < 0) {
barleft = 0;
} else if (barleft > scroll_voice.offsetWidth - bar_voice.offsetWidth) {
barleft = scroll_voice.offsetWidth - bar_voice.offsetWidth;
}
drag_voice_playPercent = parseInt(barleft / (scroll_voice.offsetWidth - bar_voice.offsetWidth) * 100);
mask_voice.style.width = drag_voice_playPercent + '%';
bar_voice.style.left = drag_voice_playPercent + "%";
})
$('body').on('mouseup', function () {
$('body').off();
...
})
}
}
複製代碼
5. Angular6 -- 實現列表拖拽和排序
<div *ngFor="let item of printList;let i = index;" (dragover)="dragover($event)" (drop)="drop($event, i)">
<div [draggable]="draggable" (dragstart)="dragstart($event, i)"></div>
</div>
複製代碼
dragstart(ev: DragEvent, index) {
ev.dataTransfer.setData('Text', index);
}
dragover(e: Event) {
e.preventDefault();
}
drop(e: DragEvent, endIndex) {
e.preventDefault();
const startIndex = e.dataTransfer.getData('Text');
const tmp = this.printList[startIndex];
this.printList[startIndex] = this.printList[endIndex];
this.printList[endIndex] = tmp;
}
複製代碼
6. 美化原生滾動軸樣式
<div class="m-video-list-wrapper" id="scrollPosition">
<div class="videoItem">
<img src="image/list4.png" alt="">
<div class="m-list-time">20:13</div>
<div class="m-list-name">視頻一 201812180841</div>
</div>
...
</div>
複製代碼
.m-video-list-wrapper{
height: 732px;
overflow-y: auto;
overflow-x: hidden;
}
.m-video-list-wrapper::-webkit-scrollbar {
width: 8px;
height: 10px;
}
.m-video-list-wrapper::-webkit-scrollbar-track {
border-radius: 0px;
background-color: #eee;
}
.m-video-list-wrapper::-webkit-scrollbar-thumb {
border-radius: 5px;
background: rgba(0,0,0,0.2);
}
複製代碼