我正在使用这个裁剪工具https://github.com/fengyuanchen/cropper/。我有这个问题,如果我动态添加图像,图像周围会有一些透明背景。因此图像不适合容器,并且还可以在图像周围进行裁剪。我按照文档中的示例尝试摆脱透明背景,但没有成功。
这是我的代码:
<div id="imgWrap" style="max-height:400px;min-height:400px">
<img id="img" src="" /> // Image gets added dynamically
</div>
Run Code Online (Sandbox Code Playgroud)
javascript
var reader = new FileReader();
reader.onloadend = function () {
var img = $('#imgWrap img');
img.attr('src', reader.result);
img.cropper({
aspectRatio: 1 / 1,
autoCropArea: 0.65,
guides: false,
strict: true,
highlight: false,
responsive:true,
dragCrop: false,
movable: true,
resizable: true,
zoomable: true,
touchDragZoom:true,
rotatable: false,
minCropBoxWidth:105,
minCropBoxHeight:105,
built: function () {
// cropper-container is the element where the image is placed
$('.cropper-container').cropper('setCanvasData', {
left: 0, …
Run Code Online (Sandbox Code Playgroud) 是否有人知道如何使用从特定维基百科页面上的表中Wikipedia API
获取JSON
或XML
数据?
有没有不同的方法来做到这一点?
例如从这里开始 https://en.wikipedia.org/wiki/List_of_action_films_of_the_2010s
我想从选择列表中获取默认选项的数据属性.
我有这个:
<select className="form-control" id="select" onChange={(e) => state.selectedOptionValue(e)} value={state.selectedOption}>
{data.map((option, i) => <Options key={i} option={option}/>)}
</select>
const Options = observer(({ state, option }) => (
<option data-option-id={option.id} value={option.displayText}>
{option.displayText}
</option>
))
Run Code Online (Sandbox Code Playgroud)
然后在我的状态文件中我有onChange
处理程序:
async selectedOptionValue (e) {
this.selectedOption = e.target.value
this.optionId = e.target.options[e.target.selectedIndex].getAttribute('data-option-id');
}
Run Code Online (Sandbox Code Playgroud)
到目前为止这工作正常,但我需要this.optionId
默认设置,所以我必须data-options-id
在渲染上获取第一个选项
我怎样才能做到这一点?
我想用点替换(数字)字符串的所有逗号,并同时添加另一个元素以显示货币
到目前为止,我有这个
$("#myelement").text(function () {
return $(this).text().replace(/\,/g, '.');
});
Run Code Online (Sandbox Code Playgroud)
到目前为止,这个工程并返回例如1,234,567
作为1.234.567
,但我怎么能串/元素添加进去,使我得到1.234.567 Dollars
或1.234.567 Rupis
等.
我正在使用laravel-nova
该Image
领域的一项资源:
use Laravel\Nova\Fields\Image;
Image::make('Top Image', 'hero_image')
->help('Upload an image to display as hero')
->disk('local')
->maxWidth(400)
->prunable()
->rules('required')
->hideFromIndex(),
Run Code Online (Sandbox Code Playgroud)
到目前为止一切顺利,但由于它是必需的,所以每次我想编辑资源时都必须上传(相同的)图像,这有点烦人,我不想让它不需要。
那么,有没有办法解决这个问题?
我正在构建一个laravel
应用程序,我想在其中包含一些schema.org
结构化数据。在我的app.blade.php
文件(一个布局文件)中,我包含了以下内容:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"name": "thecompany.com",
"alternateName": "the company",
"url": "{{ route('home') }}"
}
</script>
Run Code Online (Sandbox Code Playgroud)
现在我想添加不同的参数,取决于我在哪个子页面上。例如,我有一个职位列表页面,我希望每个职位页面都具有以下内容:
{
"@context" : "https://schema.org/",
"@type" : "JobPosting",
"title" : "Software Engineer",
"description" : "<p>Become our next developer.</p>",
"employmentType" : "CONTRACTOR",
"hiringOrganization" : {
"@type" : "Organization",
"name" : "The Company",
"sameAs" : "http://www.google.com",
"logo" : "http://www.example.com/images/logo.png",
"baseSalary": {
"@type": "MonetaryAmount",
"currency": "USD",
"value": {
"@type": "QuantitativeValue",
"value": 40.00,
"unitText": "HOUR"
}
}
}
Run Code Online (Sandbox Code Playgroud)
当然,值的变化取决于您所在的工作页面。 …
我用于webpack
一个小型应用程序,到目前为止它运行得很好,除了在显示图像时遇到问题 - 我得到了 404。
这是我的 webpack 配置:
const path = require("path");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
entry: {
index: './src/index.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js'
},
module: {
rules: [
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: 'css-loader', options: { importLoaders: 2, sourceMap: true } },
{ loader: 'postcss-loader', options: { sourceMap: true } },
{ loader: 'sass-loader', options: { implementation: require('sass'), sourceMap: true } },
]
}, …
Run Code Online (Sandbox Code Playgroud) 在我的nextjs
-app 中,我使用useEffect
和useState
-hooks 来获取一些数据:
export default function PricingBlock({ data }) {
const [pricingItems, setPricingItems] = useState()
const [featuredItem, setFeaturedItem] = useState()
useEffect(() => {
const getPricingItems = async () => {
const pricingItems = await request({ query: PRICING, variables: {} })
const items = await pricingItems?.allSpecialistPages
const featured = pricingItems?.specialistLandingpage?.card[0]
setPricingItems(items)
setFeaturedItem(featured)
}
getPricingItems()
}, [featuredItem, pricingItems])
return (
<div>
<div
style={{
backgroundColor: featuredItem?.backgroundColor?.hex,
backgroundImage: `url(${featuredItem?.backgroundImage?.url})`,
borderTop: '1px solid ' + featuredItem?.backgroundColor?.hex,
borderLeft: '1px solid …
Run Code Online (Sandbox Code Playgroud) 我想自定义我archive-products.php
的woocommerce
商店。产品显然是<ul>
. 现在我想改变它,但我找不到<ul>
任何地方。我看了看里面,content-products.php
但在这里我只找到了<li>
元素。
有人可以帮我吗?我怎样才能摆脱<ul>
?
当我替换字符串的空格、点和逗号时,有时会出现双连字符。
例如转check out the 1. place
成check-out-the-1--place
我怎样才能避免这种情况?我希望它是check-out-the-1-place
- 这样每个单词之间只有一个连字符。这是我的代码:
str_replace([' ', ',', '.','?'], '-', strtolower($pathname));
Run Code Online (Sandbox Code Playgroud)
现在,我知道为什么它会返回双连字符,但我不知道如何解决这个问题。
有人可以帮我吗?
javascript ×4
php ×4
jquery ×2
laravel ×2
reactjs ×2
crop ×1
css ×1
image ×1
json ×1
laravel-nova ×1
next.js ×1
regex ×1
schema.org ×1
str-replace ×1
string ×1
webpack ×1
webpack-5 ×1
woocommerce ×1
wordpress ×1
xml ×1