clip:rect('top', 'right', 'bottom', 'left')

本文详细介绍了CSS中clip属性的用法,包括如何定义对象的可视区域,以及如何通过上-右-下-左顺序设置偏移值实现特定的剪切效果。必须将position属性设为absolute才能使用此属性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

clip属性检索或设置对象的可视区域。区域外的部分是透明的。
必须将position的值设为absolute,此属性方可使用。

依据上-右-下-左的顺序提供自对象左上角为(0,0)坐标计算的四个偏移数值,其中任一数值都可用auto替换,即此边不剪切。

示例:clip:rect(auto 50px 20px auto);
说明:上边不剪切,右边从第50个像素开始剪切直至最右边,下边从第20个像素开始剪切直至最底部,左边不剪切。 
/* * QML Material - An application framework implementing Material Design. * * Copyright (C) 2014-2016 Michael Spencer <sonrisesoftware@gmail.com> * 2015 Ricardo Vieira <ricardo.vieira@tecnico.ulisboa.pt> * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import QtQuick 2.4 import QtQuick.Controls 1.3 as Controls import QtQuick.Controls.Styles 1.4 import Ui 1.0 as Ui import QtGraphicalEffects 1.15 /*! \qmltype ProgressBar \inqmlmodule Material \brief Visual indicator of progress in some operation. */ Controls.ProgressBar { /*! The color for the progress bar. By default this is the primary color defined in \l Theme::primaryColor */ property color color: "#00a5ff" property bool enableAnimation:true width: Ui.Device.wRate*200 height: Ui.Device.hRate*30 style: ProgressBarStyle { id: progressBarStyle progress: Rectangle { color: control.indeterminate ? "transparent" : control.color // Indeterminate animation Item { id: independentRect anchors.fill: parent visible: control.indeterminate Rectangle { id: rect height: parent.height radius: 20 color: "transparent" layer.enabled: true layer.smooth: true property real end: 0 function calculateWidth(p) { if (p <= 0.5) { return 2 * p * (control.width * 0.5); } else { return 2 * (1 - p) * (control.width * 0.5); } } function calculateX(p) { return p * control.width; } x: calculateX(rect.end) width: { let w = calculateWidth(rect.end); let maxWidth = control.width - x; return Math.min(w, maxWidth); } ShaderEffect { anchors.fill: parent fragmentShader: " varying highp vec2 qt_TexCoord0; uniform lowp vec4 color1; uniform lowp vec4 color2; void main() { gl_FragColor = mix(color1, color2, qt_TexCoord0.x); }" property color color1: "#5691F2" property color color2: "#00F6FF" } } SequentialAnimation { id: mainAnimation running: control.enableAnimation loops: Animation.Infinite NumberAnimation { target: control property: "end" from: 0 to: 1 duration: 1500 easing.type: Easing.InCubic } PauseAnimation { duration: 500 } ScriptAction { script: { rect.end = 0; rect.x = 0; } } } } } panel: Item { property bool horizontal: control.orientation === Qt.Horizontal implicitWidth: horizontal ? backgroundLoader.implicitWidth : backgroundLoader.implicitHeight implicitHeight: horizontal ? backgroundLoader.implicitHeight : backgroundLoader.implicitWidth Item { width: horizontal ? parent.width : parent.height height: !horizontal ? parent.width : parent.height y: horizontal ? 0 : width rotation: horizontal ? 0 : -90 transformOrigin: Item.TopLeft Rectangle { id: backgroundLoader implicitWidth: control.width implicitHeight: control.height color: control.color opacity: 0.2 radius: 20 } Loader { sourceComponent: progressBarStyle.progress anchors.topMargin: padding.top anchors.leftMargin: padding.left anchors.rightMargin: padding.right anchors.bottomMargin: padding.bottom anchors.top: parent.top anchors.left: parent.left anchors.bottom: parent.bottom width: currentProgress * (parent.width - padding.left - padding.right) } Text { id:tips color: "black" text: control.indeterminate ? "" : formatFloat(currentProgress*100) + "%" anchors.centerIn: parent } } } } function formatFloat(p) { var num = new Number num = p return num.toFixed(0) } }
最新发布
06-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值